import {ARR_METHODS} from "./config";
import observeArr from "./observeArr";

let originArrMethods = Array.prototype
let arrMethods = Object.create(originArrMethods)
console.log(originArrMethods, arrMethods, originArrMethods === arrMethods)

ARR_METHODS.map(m=>{
    arrMethods[m] = function (){
        let args = Array.prototype.slice.call(arguments)
        let rt = originArrMethods[m].apply(this, args)

        let newArr;
        switch (m){
            case 'push':
            case 'unshift':
                newArr = args
                break
            case 'splice':
                newArr = args.slice(2)
                break
            default:
                break
        }

        newArr && observeArr(newArr)

        return rt
    }
})

export {arrMethods}